{% block sw_single_select %}
<sw-select-base
    ref="selectBase"
    class="sw-single-select"
    :is-loading="isLoading"
    v-bind="$attrs"
    :label="label"
    @clear="clearSelection"
    @select-expanded="onSelectExpanded"
    @select-collapsed="onSelectCollapsed"
>
    {% block sw_single_select_base %}
    {% block sw_single_select_base_selection %}
    <template #sw-select-selection="{ identification, error, disabled, size, setFocusClass, removeFocusClass }">
        {% block sw_single_select_base_selection_slot %}
        <div class="sw-single-select__selection">
            {% block sw_single_select_single_selection_inner %}
            {% block sw_single_select_single_selection_inner_label %}
            <div
                v-show="!isExpanded"
                class="sw-single-select__selection-text"
                :class="selectionTextClasses"
            >
                <template v-if="singleSelection">
                    <slot
                        name="selection-label-property"
                        v-bind="{ item: singleSelection, labelProperty, valueProperty, searchTerm, getKey }"
                    >
                        <!-- !isExpanded check is needed here for fixing acceptance test "getByText" selector -->
                        {{ !isExpanded ? getKey(singleSelection, labelProperty) : '' }}
                    </slot>
                </template>
                <template v-else>
                    {{ placeholder }}
                </template>
            </div>
            {% endblock %}
            {% block sw_single_select_single_selection_inner_input %}
            <!-- eslint-disable-next-line vuejs-accessibility/form-control-has-label -->
            <input
                v-show="isExpanded"
                ref="swSelectInput"
                v-model="searchTerm"
                class="sw-single-select__selection-input"
                :class="inputClasses"
                type="text"
                :aria-label="label"
                :placeholder="placeholder"
                :disabled="disableSearchFunction"
                @input="onInputSearchTerm"
            >
            {% endblock %}
            {% endblock %}
        </div>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_single_select_base_results %}
    <template #results-list>
        {% block sw_single_select_base_results_slot %}
        <sw-select-result-list
            ref="resultsList"
            :popover-classes="popoverClasses"
            :options="visibleResults"
            :is-loading="isLoading"
            :empty-message="$tc('global.sw-single-select.messageNoResults', { term: searchTerm }, 0)"
            :focus-el="$refs.swSelectInput"
            @paginate="$emit('paginate')"
            @item-select="setValue"
        >
            {% block sw_single_select_base_results_list %}
            {% block sw_single_select_base_results_list_before %}
            <template #before-item-list>
                <slot name="before-item-list"></slot>
            </template>
            {% endblock %}

            {% block sw_single_select_base_results_list_result %}
            <template #result-item="{ item, index }">
                <slot
                    name="result-item"
                    v-bind="{ item, index, labelProperty, searchTerm, highlightSearchTerm, isSelected, setValue, getKey }"
                >
                    <sw-select-result
                        :disabled="item.disabled"
                        :class="'sw-select-option--' + item.value"
                        :selected="isSelected(item)"
                        v-bind="{ item, index }"
                        @item-select="setValue"
                    >
                        {% block sw_single_select_base_results_list_result_label %}
                        <slot
                            name="result-label-property"
                            v-bind="{ item, index, labelProperty, valueProperty, searchTerm, highlightSearchTerm, getKey }"
                        >
                            <sw-highlight-text
                                v-if="highlightSearchTerm && !isSelected(item)"
                                :text="getKey(item, labelProperty)"
                                :search-term="searchTerm"
                            />
                            <template v-else>
                                {{ getKey(item, labelProperty) }}
                            </template>
                        </slot>
                        {% endblock %}
                    </sw-select-result>
                </slot>
            </template>
            {% endblock %}

            {% block sw_single_select_base_results_list_after %}
            <template #after-item-list>
                <slot name="after-item-list"></slot>
            </template>
            {% endblock %}
            {% endblock %}
        </sw-select-result-list>
        {% endblock %}
    </template>
    {% endblock %}
    {% endblock %}

    <template #label>
        <slot name="label"></slot>
    </template>

    <template #hint>
        <slot name="hint"></slot>
    </template>
</sw-select-base>
{% endblock %}
